home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cbibcode.arc
/
FSETPOS.C
< prev
next >
Wrap
Text File
|
1991-08-05
|
934b
|
32 lines
/* fsetpos.c, from p. 436 of Turbo C Bible */
#include <stdio.h>
main()
{
fpos_t curpos;
FILE *infile;
char filename[81], buffer1[20], buffer2[20];
printf("Enter name of a text file: ");
gets(filename);
/* Open the file for reading */
if ((infile = fopen(filename, "r")) == NULL)
{
printf("fopen failed.\n");
exit(0);
}
/* Save current position *
if (fgetpos(*infile, &curpos) != ))
perror("fgetpos failed!");
/* Read 10 characters */
if (fgets(buffer1, 10 , infile) == NULL)
perror("fgets failed");
/* Reset to privious position in file */
if (fsetpos(infile, &curpos) != 0)
perror("fsetpos failed!");
/* Read another 10 characters -- */
/* these should be same as last 10. */
if (fgets(buffer2, 10, infile) == NULL)
perror("fgets failed");
printf("We read:\n");
puts(buffer1);
puts(buffer2);
}